package day4.problem1;

import java.util.Scanner;

//Fibonacci数列
//https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0, b = 1, c = 1;
        //获取小于n的和大于n的第一个fib数
        while(c < n) {
            c = a + b;
            a = b;
            b = c;
            // System.out.println(a + " " + b + " " + c);
        }
        int ret = Math.min(c-n, n-a);
        System.out.println(ret);
    }
}